package operation;

import book.Book;
import book.Booklist;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wx
 * Date: 2023-11-14
 * Time: 14:59
 */
public class BorrowOperation implements IOPeration{


    @Override
    public void work(Booklist booklist) {


        System.out.println("*******  借阅图书:  *******");

        System.out.println("**** 请输入要借阅图书: ****");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int currentSize = booklist.getUsedsize();

        for (int i = 0; i < currentSize; i++) {
            Book book = booklist.getbook(i);
            if (book.getName().equals(name)) {
                book.setIsborrowed(true);
                System.out.println("*******  借阅成功!  *******");
                System.out.println(book);
                return;
                }
            }

            System.out.println("没有这本书");

        }
    }

